
<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$app_id = $_GET['idapp'];
$sql = "Select * from app where id='" . $app_id . "'";
$rs = mysqli_query($conn, $sql);
$r = mysqli_fetch_assoc($rs);
// echo "App id" . $r['id'] . "<br>";
// echo "Name " . $r['name'] . "<br>";
// echo "Des" . $r['description'] . "<br>";

?>

<script type="text/javascript">

	
	jQuery(document).ready(function() {
		$("abbr.timeago").timeago();
	});

      $(document).ready(function(){  
          $("#btn_submit").click(function() {
                    <?php 
                        if (!empty($_SESSION['uname'])) {
                            ?>
                                
                                
                            <?php     
                            $user_id = $_SESSION['iduser'];
                            
                        }else{
                            ?>
                            alert("Please login or register");
                            return false;
                            <?php
                            
                        }
                        ?>

                var app_id = "<?= $_GET['idapp']; ?>";
                var user_id = "<?= $_SESSION['iduser']; ?>";
                var uname = "<?= $_SESSION['uname']; ?>";
                var comment = $("#comment").val();



    var dataString = 'app_id='+ app_id + '&user_id=' + user_id + '&comment=' + comment+'&uname='+uname;

    if(comment=='')
    {
          alert('Please Give Valide Details');
    }
    else
    {
          $("#flash").show();
          $("#flash").fadeIn(400).html('<img src="img/loading_1.gif" align="absmiddle">&nbsp;<span class="loading">Loading Comment...</span>');
          $.ajax({
          type: "POST",
          url: "modules/commentajax.php",
          data: dataString,
          cache: false,
          success: function(html){

          $("ol#update").append(html);
          $("ol#update li:last").fadeIn("slow");					

          document.getElementById('comment').value='';
          $("#comment").focus();
          $("#flash").hide();
          $("abbr.timeago").timeago();

    }
    });
    }
    return false;
});
});

</script>

<!-- <link type="text/javascript" href="localtime.js" /> -->
<div id="app-detail">
    <div class="icon-detail">
      <img src="img/app/<?php echo $r['image']?>" />
	<h3><?php echo $r['name']; ?></h3><br/>
      <a href="<?php echo $r['link']?>">Download</a>
    </div>
    <div class="screenshot-detail">
        <img src="<?php echo $r['screenshot']?>"/>
    </div>
    <div class="description-detail">
        <br/>
        <h3 style="color: #009">Description</h3>
        <?php echo $r['description']; ?>
    </div>
    <br/>
	<h3 style="color: #009">User review</h3>
	
</div>


<ol  id="update" class="timeline">

	<?php
    //increase view by 1
	$result = mysqli_query($conn, "select * from app where id='$app_id'");
	$row = mysqli_fetch_assoc($result);
	$viewcount = $row['view'] + 1;
	mysqli_query($conn, "update app set view='$viewcount' where id='$app_id'");
//$post_id value comes from the POSTS table
	$sql1 = "select * from comment where app_id='$app_id'";

	$rs1 = mysqli_query($conn, $sql1);

	while ($row = mysqli_fetch_assoc($rs1)) {
        //echo "in while loop";
		$app_id = $row['app_id'];
		$user_id = $row['user_id'];
		$comment = $row['comment'];
		$dtime=$row['time'];
		$atime="<abbr class='timeago' title='$dtime'></abbr>";

        //get user name from user id
		$rs2 = mysqli_query($conn, "select * from user where id='$user_id'");
		$row_temp = mysqli_fetch_assoc($rs2);
		$name = $row_temp['name'];
		?>
		<li class="box" style="display: list-item;">
			<img src="http://www.oeic.us/img/site/icons/default_avatar.gif" class="com_img"/><span  class="com_name"> <?php echo $name; ?></span>  <?php echo $atime; ?> <br /><br />

			<?php echo $comment; ?>
		</li>

		<?php
	}
	?>

</ol>
<div id="flash" align="left"  ></div>

<div style="margin-left:100px">
	
	<form action="#" method="post">

		<textarea name="comment" id="comment"></textarea><br />

		<input type="submit" id="btn_submit" class="submit" value=" Submit Comment " />
	</form>
</div>


